home *** CD-ROM | disk | FTP | other *** search
- // Dynamic link library implementation of NeuroSolutions L1Criterion component
-
- #include "NSDLL.h"
-
- /***********************************/
- /* Forward activation of component */
-
- __declspec(dllexport) NSFloat performCriterion(
- DLLData *instance, // Pointer to instance data (may be NULL)
- NSFloat *costDerivative, // Pointer to the cost derivative vector, i.e. output sensitivity
- int rows, // Number of rows of PEs in the layer
- int cols, // Number of columns of PEs in the layer
- NSFloat *output, // Pointer to the output layer of the network
- NSFloat *desired, // Pointer to the desired output vector, same length as output layer
- BOOL testing // Flag to indicate whether or not the data is for the test set
- )
- {
- int i,length=rows*cols;
- NSFloat cost=0.0f;
- NSFloat error;
-
- for (i=0; i<length; i++) {
- error = desired[i] - output[i];
- costDerivative[i] = error < 0.0f ? -1.0f : error > 0.0f ? 1.0f : 0.0f;
- cost += (NSFloat)fabs(error);
- }
- return cost;
- }
-
- /******************************************/
- /* Management of instance data (OPTIONAL) */
- /*
- __declspec(dllexport) DLLData *allocCriterion(
- DLLData *oldInstance, // Pointer to the last instance if reallocating
- int rows, // Number of rows of PEs in the layer
- int cols // Number of columns of PEs in the layer
- )
- {
- DLLData *instance = allocDLLInstance(oldInstance);
- return instance;
- }
-
- __declspec(dllexport) void freeCriterion(DLLData *instance)
- {
- freeDLLInstance(instance);
- }
- */
-